<template>
  <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="80px">
    <el-form-item label="所属学校:" prop="schoolId">
      <el-select
        v-model="queryParams.schoolId"
        placeholder="请选择所属学校"
        clearable
        filterable
        default-first-option
        remote
        :remote-method="schoolSelect"
        :loading="loadingSelect"
      >
        <el-option
          v-for="item in schoolOptions"
          :key="item.schoolId"
          :label="item.schoolName"
          :value="item.schoolId"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="学生姓名:" prop="studentName">
      <el-input
        v-model="queryParams.studentName"
        placeholder="请输入学生姓名"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="性别:" prop="sex">
      <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable >
        <el-option
          v-for="dict in sexOptions"
          :key="dict.dictValue"
          :label="dict.dictLabel"
          :value="dict.dictValue"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="联系电话:" prop="phone">
      <el-input
        v-model="queryParams.phone"
        placeholder="请输入联系电话"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary"  size="mini" @click="handleQuery"> <Edit /> 搜索</el-button>
      <el-button  size="mini" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>

  <el-row :gutter="10" class="mb8">
    <el-col :span="1.5">
      <el-button
        v-hasPermi="['sc:student:add']"
        type="primary"
        size="mini"
        @click="handleAdd"
      > <el-icon><Plus /></el-icon> 新增</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        v-hasPermi="['sc:student:update']"
        type="primary"
        :disabled="single"
        @click="handleUpdate"
      >
        <el-icon><Edit /></el-icon>
        修改</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        v-hasPermi="['sc:student:delete']"
        type="danger"
        :disabled="multiple"
        @click="handleDelete"
      >
        <el-icon><Delete /></el-icon>
        删除</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        v-hasPermi="['sc:student:list']"
        type="primary"
        @click="handleImport"
      >
        <el-icon><UploadFilled /></el-icon>
        批量导入
      </el-button>
    </el-col>
  </el-row>
  <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center" />
    <el-table-column prop="studentName" label="学生姓名">

      <template #default="scope">
        <span @click="handleGo(scope.row)">{{ scope.row.studentName }}</span>
<!--        <router-link :to="'/edu/student/detail/' + scope.row.studentId" class="link-type">-->
<!--          <span>{{ scope.row.studentName }}</span>-->
<!--        </router-link>-->
      </template>
    </el-table-column>
    <el-table-column prop="schoolName" label="所属学校" />
    <el-table-column prop="birthDay" label="生日">
      <template #default="scope">
        <span>{{ parseTime(scope.row.birthDay, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="age" label="年龄" />
    <el-table-column prop="inTime" label="首次入校时间">
      <template #default="scope">
        <span>{{ parseTime(scope.row.inTime, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column align="center" prop="sex" label="性别" :formatter="sexFormat" />
    <el-table-column align="center" prop="phone" label="联系电话">
      <template #default="scope">
        <el-tooltip effect="dark" :content="scope.row.contactInfo" placement="top">
          <span>{{ scope.row.phone }}</span>
        </el-tooltip>
      </template>
    </el-table-column>
    <el-table-column width="250" label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
      <template #default="scope">
        <el-button
          v-hasPermi="['sc:student:update']"
          size="mini"
          type="text"
          icon="el-icon-edit-outline"
          @click="handleUpdate(scope.row)"
        >修改</el-button>
        <el-button
          v-hasPermi="['sc:student:delete']"
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
        >删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div style="display: flex;justify-content: flex-end;margin-top: 20px;">
    <el-pagination
      v-model:current-page="pagination.currentPage"
      v-model:page-size="pagination.pageSize"
      :page-sizes="pagination.pageSizes"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>

</template>

<script setup name="studentList">
  import {ref,onMounted} from 'vue'
  const queryParams=ref({

  })
  const sexOptions=[]
  const schoolOptions=[]

  onMounted(() =>{
    handleQuery()
  })

  // 查询
  const handleQuery=() => {

    console.log(pagination.value)

  }
  const resetQuery=() => {
    queryParams.value={}
    handleQuery()
  }


  const loading=ref(false)
  const dataList=ref([{
    studentName:'吴总'
  },{
    studentName:'赵总'
  }])


  // 分页
  const pagination=ref({
    currentPage:1,
    pageSize:10,
    pageSizes:[10,20,50,100],
    total:100
  })
  const handleSizeChange =(num) => {
    pagination.value.pageSize=num;
    handleQuery()
  }
  const handleCurrentChange=(num) => {
    pagination.value.currentPage=num;
    handleQuery()

  }

  // 新增
  const handleAdd=() => {

  }
  const multiple=ref(true)
  const single=ref(true)
  const ids=ref([])

  const handleSelectionChange=(selection) => {
    ids.value = selection.map(item => item.studentId)
    single.value = selection.length !== 1
    multiple.value = !selection.length
  }

  // 编辑
  const handleUpdate=() => {

  }

  // 删除
  const handleDelete=() => {
    ElMessageBox.confirm('确定删除?')
      .then(() => {
        ElMessage.success('删除成功')
        handleQuery()
      })
      .catch(() => {
        // catch error
      })

  }

  // 导入
  const handleImport=() => {

  }
  // 跳转

  const handleGo =() => {

  }

</script>

<style scoped>

</style>
